package gr.atc.epart;

import gr.atc.epart.actions.ActionComment;
import gr.atc.epart.googlewrapper.moderator.ModeratorTopic;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DeliberationTopicsAdapter extends BaseAdapter
{
	Context _context;
	ArrayList<ModeratorTopic> _topics;

	public DeliberationTopicsAdapter(Context context) 
	{
		_context = context;
		_topics = new ArrayList<ModeratorTopic>();
	}

	
	@Override
	public int getCount()
	{
		return _topics.size();
	}

	@Override
	public Object getItem(int i)
	{
		return _topics.get(i);
	}

	@Override
	public long getItemId(int i)
	{
		return i;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewgroup)
	{

		// all topics are retrieved at once..no need to implement ask-on-demand
		ModeratorTopic topic = _topics.get(i);

		View v = view;

		if (v == null) {
			LayoutInflater inflater = (LayoutInflater) _context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.topicrow, null);
		}

		if (topic != null) {
			TextView topicName = (TextView) v.findViewById(R.id.topicname);
			TextView topicDescription = (TextView) v.findViewById(R.id.topicdescription);

			topicName.setText(topic.getName());
			topicDescription.setText(topic.getDescription());
		}

		return v;
	}
	
	public ArrayList<ModeratorTopic> getTopics()
	{
		return _topics;
	}


	public void setTopics(ArrayList<ModeratorTopic> topics)
	{
		_topics = topics;
		this.notifyDataSetChanged();
	}


}
